package com.erp.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.erp.dto.Apply;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
// JOINED 是将父类、子类分别存放在不同的表中，并且建立相应的外键，以确定相互之间的关系。
@Table(name = "t_apply")
public class TApply implements java.io.Serializable {

	private static final long serialVersionUID = 1L;

	private Integer id;
	private TUser tApplicant;// 申请人
	private Date applyTime;// 申请时间
	private String title;// 申请标题
	private Integer status;// 申请状态
	private String procInstId;// 流程实例ID
	private List<TExamine> tExamineList = new ArrayList<TExamine>();

	public TApply() {
	}

	public TApply(Apply apply) {
		this.id = apply.getId();
		this.tApplicant = new TUser(apply.getApplicant());
		this.applyTime = apply.getApplyTime();
		this.title = apply.getTitle();
		this.status = apply.getStatus();
		this.procInstId = apply.getProcInstId();
	}

	@Id
	@GeneratedValue
	@Column(name = "id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * TApplicant属性，本类与TUser是多对一单向关系
	 * 
	 * @return
	 */
	@ManyToOne
	@JoinColumn(name = "applicant_id")
	public TUser gettApplicant() {
		return tApplicant;
	}

	public void settApplicant(TUser tApplicant) {
		this.tApplicant = tApplicant;
	}

	@Column(name = "applyTime")
	public Date getApplyTime() {
		return applyTime;
	}

	public void setApplyTime(Date applyTime) {
		this.applyTime = applyTime;
	}

	@Column(name = "title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "status")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Column(name = "procInstId")
	public String getProcInstId() {
		return procInstId;
	}

	public void setProcInstId(String procInstId) {
		this.procInstId = procInstId;
	}

	/**
	 * tExamineList属性，本类与TExamine是一对多双向关系
	 * 
	 * @return
	 */
	@OneToMany(mappedBy = "tApply", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@OrderBy(value = "examineTime ASC")
	public List<TExamine> gettExamineList() {
		return tExamineList;
	}

	public void settExamineList(List<TExamine> tExamineList) {
		this.tExamineList = tExamineList;
	}

}
